package com.software.myopiachildren.receiver;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.software.myopiachildren.utils.eb.EB;
import com.software.myopiachildren.utils.eb.EbData;

public class BluetoothStateBroadcastReceive extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        switch (action) {
            case BluetoothDevice.ACTION_ACL_CONNECTED:
//                Toast.makeText(context , "蓝牙设备:" + device.getName() + "已链接", Toast.LENGTH_SHORT).show();
                Log.e("BluetoothState", "====:" + "蓝牙设备:" + device.getName() + "已链接");
                break;
            case BluetoothDevice.ACTION_ACL_DISCONNECTED:
//                Toast.makeText(context , "蓝牙设备:" + device.getName() + "已断开", Toast.LENGTH_SHORT).show();
                Log.e("BluetoothState", "====:" + "蓝牙设备:" + device.getName() + "已断开");
                break;
            case BluetoothAdapter.ACTION_STATE_CHANGED:
                int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
                switch (blueState) {
                    case BluetoothAdapter.STATE_OFF:
//                        Toast.makeText(context , "蓝牙已关闭", Toast.LENGTH_SHORT).show();
                        Log.e("BluetoothState", "====:" + "蓝牙已关闭:");
                        EB.post(new EbData(31));
                        break;
                    case BluetoothAdapter.STATE_ON:
//                        Toast.makeText(context , "蓝牙已开启"  , Toast.LENGTH_SHORT).show();
                        Log.e("BluetoothState", "====:" + "蓝牙已开启:");
                        EB.post(new EbData(32));
                        break;
                }
                break;
        }
    }
}

